cmake_minimum_required(VERSION 3.0)

project(CHAT_SERVER)

set(CMAKE_VERBOSE_MAKEFILE ON) #显示编码详细内容
set(CMAKE_BUILD_TYPE Debug)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_COMPILER g++-13)
set(CMAKE_CXX_FLAGS "-Wall")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#=========================================================
# LoginServer 程序
set(LoginServerFile 
    LoginServer/main.cpp
    utilities.cpp
    LoginServer/LoginServer.cpp
    LoginServer/HttpConnection.cpp
    LoginServer/Logic.cpp
    protos/message.grpc.pb.cc
    protos/message.pb.cc
    GrpcClient/VerifyGrpcClient.cpp
    ConfigMgr.cpp
    AsioIoContextPool.cpp
    DB/Redis/RedisMgr.cpp
    DB/Redis/RedisConPool.cpp
    DB/MySql/MySqlConPool.cpp
    DB/MySql/MysqlDaoBase.cpp
    Hash.cpp
    GrpcClient/StatusGrpcClient.cpp
)

# 找 gRPC & Protobuf
find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)

add_executable(LoginServer ${LoginServerFile})

target_link_libraries(LoginServer
    # 链接 gRPC 和 Protobuf
    PRIVATE
    gRPC::grpc++
    gRPC::grpc
    protobuf::libprotobuf
    protobuf::libprotoc

    #链接 redis
    hiredis
    #链接 mysql
    mysqlclient
    #链接 OpenSSL
    crypto
)

#=========================================================
# ChatServer 程序
set(ChatServerFile 
    ChatServer/main.cpp
    ChatServer/ChatServer.cpp
    ChatServer/Session.cpp
    ChatServer/Logic.cpp
    ChatServer/MsgNode.cpp
    ConfigMgr.cpp
    AsioIoContextPool.cpp
    protos/message.grpc.pb.cc
    protos/message.pb.cc
    GrpcClient/StatusGrpcClient.cpp
    DB/MySql/MySqlConPool.cpp
    DB/MySql/MysqlDaoBase.cpp
)

add_executable(ChatServer ${ChatServerFile})

target_link_libraries(ChatServer
    # 链接 gRPC 和 Protobuf
    PRIVATE
    gRPC::grpc++
    gRPC::grpc
    protobuf::libprotobuf
    protobuf::libprotoc

    #链接 mysql
    mysqlclient
)

#=========================================================
# StatusServer 程序
set(StatusServerFile
    StatusServer/main.cpp
    StatusServer/StatusServer.cpp
    protos/message.grpc.pb.cc
    protos/message.pb.cc
    ConfigMgr.cpp
)
add_executable(StatusServer ${StatusServerFile})

target_link_libraries(StatusServer
    # 链接 gRPC 和 Protobuf
    PRIVATE
    gRPC::grpc++
    gRPC::grpc
    protobuf::libprotobuf
    protobuf::libprotoc
)
#=========================================================

#测试 Redis 程序
set(testRedisFile
    DB/Redis/TestRedis.cpp
    DB/Redis/RedisMgr.cpp
    DB/Redis/RedisConPool.cpp
    ConfigMgr.cpp
)

add_executable(testRedis ${testRedisFile})

target_link_libraries(testRedis
    #链接 redis
    hiredis
)

#=========================================================

#测试 mysql 程序

set(testMySqlFile
    DB/MySql/TestMySql.cpp
    DB/MySql/MySqlConPool.cpp
    DB/MySql/MysqlDaoBase.cpp
    ConfigMgr.cpp
)

add_executable(testMysql ${testMySqlFile})

target_link_libraries(testMysql
    #链接 mysql
    mysqlclient
)
